import request from '@/utils/axios'

interface ManageRes<T> {
    code?: number
    data: T
    count?:number
    username:string
    error?:string
}
type PromiseRes<T = {}> = Promise<ManageRes<T>>
interface adminLoginRes {
  token:string
  avatar:string
}
interface adminLoginListRes{
  pk: string
  fields: {
    email: string
    nickname: string
    phone: string
    sign: string
    avatar: string
    age:number
    sex:number

  }
}
// interface goodsListRes{
//   g_id:string
//   c_id:string
//   g_name:string
//   g_img: string
//   g_price: number
//   g_info: string
//   g_count: number
// }

interface classAddListApiRes{
  c_name:string
  c_info:string
  c_parent_id: number
  level: string
}
// 管理员
// 管理员注册
export const adminRegisterApi = (data: API.adminRegisterData):PromiseRes<{}> => request.post('/admin', data)
// 管理员登录
export const adminLoginApi = (data: API.adminLoginData):PromiseRes<adminLoginRes> => request.post('/login', data)
// 管理员列表获取
export const adminLoginListApi = (currentPage:number, pagesize:number):PromiseRes<adminLoginListRes[]> => request.get('/admin', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 单个管理员获取
export const adminLoginOneApi = (username:string):PromiseRes<API.adminLoginOneRes> => request.get( `/admin/${username}`)
// 修改管理员
export const adminUpdataApi = (username:string,data:API.adminLoginOneRes):PromiseRes<API.adminLoginOneRes> => request.put( `/admin/${username}`, data)
// 删除管理员
export const adminDeleteApi = (username:string,data:string):PromiseRes<API.adminLoginOneRes> => request.delete( `/admin/${data}`,{ data:{"username":username} })

// 用户
// 用户注册
// export const adminRegisterApi = (data: API.adminRegisterData):PromiseRes<{}> => request.post('/admin', data)
// 用户登录
// export const adminLoginApi = (data: API.adminLoginData):PromiseRes<adminLoginRes> => request.post('/login', data)
// 用户列表获取
export const userLoginListApi = (currentPage:number, pagesize:number):PromiseRes<adminLoginListRes[]> => request.get('/user', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 单个用户获取
export const userLoginOneApi = (username:string):PromiseRes<API.adminLoginOneRes> => request.get( `/user/${username}`)
// 修改用户
export const userUpdataApi = (username:string,data:API.adminLoginOneRes):PromiseRes<API.adminLoginOneRes> => request.put( `/user/${username}`, data)
// 删除用户
export const userDeleteApi = (username:string,data:string):PromiseRes<API.adminLoginOneRes> => request.delete( `/user/${data}`,{ data:{"username":username} })

// 分类
// 分类列表获取
export const classListApi = ():PromiseRes<API.classListRes[]> => request.get('/class')
// 单个分类列表获取
export const classListOneApi = (nid:number):PromiseRes<API.classListData> => request.get('/class/' + nid)
// 类id及名字获取
export const classParentIdListApi = (nid:number|string):PromiseRes<API.classListRes[]> => request.get('/class/parentid/'+nid)
// 添加分类
export const classAddListApi = (data:classAddListApiRes):PromiseRes<[]> => request.post('/class', data)
// 修改分类
export const classUpdatListApi = (nid: number,data:classAddListApiRes):PromiseRes<[]> => request.put('/class/'+nid, data)
// 删除分类
export const classDeleteApi = (nid: number):PromiseRes<[]> => request.delete('/class/'+nid)

// 商品
export const goodsListApi = (currentPage:number, pagesize:number):PromiseRes<API.goodsOneRes[]> => request.get('/goods', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 单个分类列表获取
export const goodsListOneApi = (nid:number):PromiseRes<API.goodsOneRes> => request.get('/goods/' + nid)
// 添加分类
export const goodsAddListApi = (data:API.goodsOneRes):PromiseRes<[]> => request.post('/goods', data)
// 修改分类
export const goodsUpdatListApi = (nid: number, data:API.goodsOneRes):PromiseRes<[]> => request.put('/goods/'+ nid, data)
// 删除分类
export const goodsDeleteApi = (nid: number):PromiseRes<[]> => request.delete('/goods/'+nid)


// 轮播图
export const bannerListApi = (currentPage:number, pagesize:number):PromiseRes<API.bannerOneRes[]> => request.get('/banner', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 添加轮播图
export const bannerAddListApi = (data:{ "banner_name":number, "banner_img": string}):PromiseRes<[]> => request.post('/banner', data)
// 单个轮播图获取
export const bannerListOneApi = (nid:number):PromiseRes<{ "banner_name":number, "banner_img": string}> => request.get('/banner/' + nid)
// 修改轮播图
export const bannerUpdatListApi = (nid: number, data:{ "banner_name":number, "banner_img": string}):PromiseRes<[]> => request.put('/banner/'+ nid, data)
// 删除轮播图
export const bannerDeleteApi = (nid: number):PromiseRes<[]> => request.delete('/banner/'+nid)

// 统计
// 销售数量
export const StatisticsSellApi = (currentPage:number, pagesize:number):PromiseRes<API.sellList[]> => request.get('/statistics/sell', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 满意度
export const StatisticsDosApi = (currentPage:number, pagesize:number):PromiseRes<API.dosList[]> => request.get('/statistics/dos', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 业绩总览
export const StatisticsPerApi = (currentPage:number, pagesize:number):PromiseRes<API.perList[]> => request.get('/statistics/per', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 往年销量
export const StatisticsOldsellApi = (currentPage:number, pagesize:number):PromiseRes<API.oldsellList[]> => request.get('/statistics/oldsell', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 用户性别占比分析
export const StatisticsAgeApi = (currentPage:number, pagesize:number):PromiseRes<API.AgeList[]> => request.get('/statistics/age', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 退货占比
export const StatisticsRetApi = (currentPage:number, pagesize:number):PromiseRes<API.RetList[]> => request.get('/statistics/ret', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 前四商品
export const StatisticsqianApi = (currentPage:number, pagesize:number):PromiseRes<API.sellList[]> => request.get('/statistics/qian', {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 市场调研
export const StatisticsMarkApi = (currentPage:number, pagesize:number):PromiseRes<API.markList[]> => request.get('/statistics/mark', {params:{"currentPage":currentPage, "pagesize": pagesize}})

// 订单
export const productOrderListApi = (currentPage:number, pagesize:number,state?:any):PromiseRes<any[]> => request.get(`/product_order`, {params:{"currentPage":currentPage, "pagesize": pagesize,"state":state}})
// 修改
export const productOrderPutApi = (username:string,data:any):PromiseRes<{}> => request.put(`/product_order/${username}`,data)
